package com.example.service.impl;

import com.example.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * @copyright (C), 2019-2022, Kkoo
 * @author: kkoo
 * @date: 2022/5/22 2:26 PM
 * @fileName: MailServiceIml
 */
@Service
public class MailServiceIml implements MailService {

    @Autowired
    private JavaMailSender sender;

    @Value("${mail.fromMail.addr}")
    private String from;


    /**
     * @param receive    邮件收件人
     * @param subject    邮件主题
     * @param verifyCode 邮件验证码
     */
    @Override
    public void sendMail(String receive, String subject, String verifyCode) {

        SimpleMailMessage message = new SimpleMailMessage();

        // 主题
        message.setSubject(subject);

        // 文本
        message.setText("暗号是：" + verifyCode);

        // 发件人
        message.setFrom(from);

        // 收件人
        message.setTo(receive);

        // 发送
        sender.send(message);
    }
}
